//
//  main.m
//  prepare lessons of NSString
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    

    /** 初始化(init) */
    // NSString *str = [[NSString alloc] initWithString:@"shanghai"];
    
    /** 便利构造器(string) */
//    NSString *str = [NSString stringWithString:@"shanghai"];
    
    /** 获取字符串长度(length) */
    NSString *str = @"shanghai";
    NSInteger length = [str length];
    
    /** 获取字符串中字符(character) */
    char str2 = [str characterAtIndex:2];
    
    /** 字符串是否相等(equal) */
    BOOL a = [str isEqualToString:@"shanghai"];
    NSLog(@"%d", a);
    
    /** 获取子串(sub) */
    NSString *str3 = @"kobe is good player";
    NSString *str4 = [str3 substringFromIndex:5];
    NSString *str5 = [str3 substringToIndex:4];
    NSRange range = NSMakeRange(0, 4);
    NSString *str6 = [str3 substringWithRange:range];
    
    /** 拼接字符串(append) */
    NSString *str7 = @"www.";
    NSString *str8 = @"baidu.com";
    NSString *str9 = [str7 stringByAppendingString:str8];
    
    /** 替换字符串(replace) */
    NSString *str10 = @"kobe";
    NSRange range1 = NSMakeRange(0, 4);
    NSString *str11 = [str10 stringByReplacingCharactersInRange:range1 withString:@"coco"];
    NSString *str12 = [str10 stringByReplacingOccurrencesOfString:@"k" withString:@"c"];
    
    /** 字符串对象转化为int类型(int) */
    NSString *str13 = @"12";
   int number = [str13 intValue];
    
    /** 字符串对象转化为其他数据类型, 例如double, float, BOOL等. */
    NSString *str14 = @"12.45";
    float number1 = [str14 floatValue];
    double number15 = [str14 doubleValue];
    BOOL b = [str14 boolValue];
    
    /** 字符串全部大写(uppercase) */
    NSString *str15 = @"beijing";
    NSString *str16 = [str15 uppercaseString];
    
    /** 字符串全部小写(lowercase) */
    NSString *str17 = @"GUANGZHOU";
    NSString *str18 = [str17 lowercaseString];
    
    /** 字符串首字母大写(capitalized) */
    NSString *str19 = @"sahnghai";
    NSString *str20 = [str19 capitalizedString];
    
    /** 是否以指定字符串为前缀(prefix) */
    NSString *str21 = @"tianjing";
    BOOL c = [str21 hasPrefix:@"tian"];
    
    /** 是否以指定字符串为后缀(suffix) */
    BOOL d = [str21 hasSuffix:@"jing"];
    
    return 0;
}
